package com.graphsql.gamesdk.base;

import android.content.res.Configuration;
import android.os.Handler;
import android.os.Message;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.graphsql.gamesdk.util.LogDebugger;

public class BaseFragmentActivity extends SherlockFragmentActivity{

	private static final String TAG = "BaseFragmentActivity";
	
//	private static ExecutorService mThreadPool = Executors
//			.newFixedThreadPool(10);
	
	protected boolean runningFlag = true;

	public boolean destroyFlag = false;
	
	public static final int UPDATE_UI = 1;
	
	public Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			if (destroyFlag) {
				return;
			}
//            LogDebugger.info(TAG,  ""+msg.what);
			switch (msg.what) {
			case UPDATE_UI:
				updateUI();
				break;
			default:
				onHandleMessage(msg);
				break;
			}
		}
	};
	protected void init() {
	}
	protected void updateUI() {
	}
	protected void onHandleMessage(Message msg) {
	}
	@Override
	public void onStart() {
		super.onStart();
		runningFlag = true;
		LogDebugger.info(TAG,"onStart");
	}

	@Override
	public void onResume() {
		super.onResume();
		runningFlag = true;
		LogDebugger.info(TAG,"onResume");
	}

	@Override
	public void onPause() {
		super.onPause();
		runningFlag = false;
		LogDebugger.info(TAG,"onPause");
	}

	@Override
	public void onStop() {
		super.onStop();
		runningFlag = false;
		LogDebugger.info(TAG,"onStop");
	}
	@Override
	public void onDestroy() {
		super.onDestroy();
		LogDebugger.info(TAG,"onDestroy");
		destroyFlag = true;
		System.gc();
	}
	public final void sendMessage(int what) {
		mHandler.sendMessage(mHandler.obtainMessage(what));
	}

	protected final void sendMessage(int what, int arg1, int arg2) {
		mHandler.sendMessage(mHandler.obtainMessage(what, arg1, arg2));
	}

	protected final void sendMessageDelayed(int what, long delayMillis) {
		mHandler.sendMessageDelayed(mHandler.obtainMessage(what), delayMillis);
	}

	protected final void sendMessageDelayed(int what, int arg1, int arg2,
			long delayMillis) {
		mHandler.sendMessageDelayed(mHandler.obtainMessage(what, arg1, arg2),
				delayMillis);
	}

	protected final void sendMessage(int what, Object obj) {
		mHandler.sendMessage(mHandler.obtainMessage(what, obj));
	}
	
	protected final void sendMessage(int what, int arg1, int arg2, Object obj) {
		mHandler.sendMessage(mHandler.obtainMessage(what, arg1, arg2, obj));
	}

	protected final void removeMessages(int what) {
		mHandler.removeMessages(what);
	}
	
	
}
